From caf34422d6e1c480417e06c6bf16d7584f5234db Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Fri, 23 Aug 2013 23:10:51 +0000 Subject: [PATCH] eliminate weird input mode of gpx reader. add a test to make sure standard input works. --- gpsbabel/gpx.cc | 39 +++++---------------------------------- gpsbabel/testo.d/gpx.test | 5 +++++ 2 files changed, 10 insertions(+), 34 deletions(-) diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 2421c0824..b9aa5818b 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -53,15 +53,12 @@ static waypoint* wpt_tmp; static UrlLink* link_; static int cache_descr_is_html; static gbfile* fd; -static const char* input_fname; static gpsbabel::File* oqfile; static gpsbabel::XmlStreamWriter* writer; static short_handle mkshort_handle; static const char* link_url = NULL; static const char* link_text = NULL; -static const char* input_string = NULL; -static int input_string_len = 0; static char* snlen = NULL; static char* suppresswhite = NULL; @@ -1290,16 +1287,7 @@ gpx_cdata(void* dta, const XML_Char* xml_el, int len) static void gpx_rd_init(const char* fname) { - if (fname[0]) { - fd = gbfopen(fname, "r", MYNAME); - input_fname = fname; - } else { - fd = NULL; - input_string = fname+1; - input_string_len = strlen(input_string); - input_fname = NULL; - } - + fd = gbfopen(fname, "r", MYNAME); current_tag.clear(); @@ -1343,7 +1331,6 @@ gpx_rd_deinit(void) psr = NULL; wpt_tmp = NULL; cur_tag = NULL; - input_fname = NULL; } #endif @@ -1378,28 +1365,12 @@ gpx_read(void) { #if HAVE_LIBEXPAT int len; - int done = 0; char* buf = (char*) xmalloc(MY_CBUF_SZ); - int result = 0; - - while (!done) { - if (fd) { - len = gbfread(buf, 1, MY_CBUF_SZ - 1, fd); - done = gbfeof(fd) || !len; - result = XML_Parse(psr, buf, len, done); - } else if (input_string) { - done = 0; - result = XML_Parse(psr, input_string, - input_string_len, done); - done = 1; - } else { - done = 1; - result = -1; - } - if (!result) { - fatal(MYNAME ": XML parse error at line %d of '%s' : %s\n", + + while ((len = gbfread(buf, 1, MY_CBUF_SZ - 1, fd))) { + if (!XML_Parse(psr, buf, len, gbfeof(fd))) { + fatal(MYNAME ":Parse error at %d: %s\n", (int) XML_GetCurrentLineNumber(psr), - input_fname ? input_fname : "unknown file", XML_ErrorString(XML_GetErrorCode(psr))); } } diff --git a/gpsbabel/testo.d/gpx.test b/gpsbabel/testo.d/gpx.test index 85d29e943..962446750 100644 --- a/gpsbabel/testo.d/gpx.test +++ b/gpsbabel/testo.d/gpx.test @@ -30,3 +30,8 @@ compare ${REFERENCE}/bigtime.gpx ${TMPDIR}/bigtime.gpx rm -f ${TMPDIR}/basecamp~gpx_so.gpx gpsbabel -i gpx -f ${REFERENCE}/basecamp.gpx -o gpx -F - 1> ${TMPDIR}/basecamp~gpx_so.gpx compare ${REFERENCE}/basecamp~gpx.gpx ${TMPDIR}/basecamp~gpx_so.gpx + +# test standard input +rm -f ${TMPDIR}/basecamp~gpx_si.gpx +gpsbabel -i gpx -f - -o gpx -F ${TMPDIR}/basecamp~gpx_si.gpx 0< ${REFERENCE}/basecamp.gpx +compare ${REFERENCE}/basecamp~gpx.gpx ${TMPDIR}/basecamp~gpx_si.gpx -- 2.30.2